package org.agridata.akvisualization.controller.ziyuan;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.agridata.akvisualization.doMain.entity.ResourceUtilization;
import org.agridata.akvisualization.doMain.vo.AnimalSaveCropVo;
import org.agridata.akvisualization.result.Result;
import org.agridata.akvisualization.service.ResourceUtilizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author: yxc
 * @date: 2024/2/19 10:11
 * @Description: 资源化利用
 */
@RestController
@RequestMapping("/resourceUtilization")
@Api(tags = "资源化利用")
public class ResourceUtilizationController {

    @Autowired
    ResourceUtilizationService resourceUtilizationService;

    @ApiOperation("资源化利用数据导入")
    @PostMapping("resourceUtilizationImport")
    public Result ResourceUtilizationImport(@RequestPart("file") MultipartFile file, String dates, String monthly){
        try {
            List<ResourceUtilization> memberList = EasyExcel.read(file.getInputStream())
                    .head(ResourceUtilization.class)
                    .sheet()
                    .doReadSync();
            return resourceUtilizationService.importResourceUtilization(memberList,dates,monthly);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.fail("出现异常");
        }
    }

    @ApiOperation("资源化利用二级页面百分比数据")
    @GetMapping("/getResourceList")
    public Result getResourceList(String data,String monthly){
        try {
            List<ResourceUtilization> resourceList = resourceUtilizationService.getResourceList(data, monthly);
            return Result.ok(resourceList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败");
        }
    }

    @ApiOperation("资源化利用首页百分比数据")
    @GetMapping("/getResourceHomePage")
    public Result getResourceHomePage(String monthly){
        try {
            return resourceUtilizationService.getResourceHomePage(monthly);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败");
        }
    }

    @ApiOperation("资源化利用表格数据")
    @GetMapping("/getResource")
    public Result getResource(String data,String monthly){
        try {
            List<Map<String,Object>> resourceList = resourceUtilizationService.getResource(data, monthly);
            return Result.ok(resourceList);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("查询失败");
        }
    }

}
